﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace EFong.Contract
{
    [DataContract]
    public class OtherBusiness
    {
        public OtherBusiness() 
        {
            OrderType = "其他";
            CustomerStatus = "未收款";
            VendorStatus = "未付款";
        }

        private Guid _id = Guid.NewGuid();
        [DataMember]
        public Guid ID
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _ref = string.Empty;
        [DataMember]
        public string Ref
        {
            get { return _ref; }
            set { _ref = value; }
        }

        private string _orderType = string.Empty;
        [DataMember]
        public string OrderType
        {
            get { return _orderType; }
            set { _orderType = value; }
        }

        private User _orderUser;
        [DataMember]
        public User OrderUser
        {
            get { return _orderUser; }
            set { _orderUser = value; }
        }

        private string _orderUserText = string.Empty;
        [DataMember]
        public string OrderUserText
        {
            get { return _orderUserText; }
            set { _orderUserText = value; }
        }

        private DateTime? _orderDate = DateTime.Now;
        [DataMember]
        public DateTime? OrderDate
        {
            get { return _orderDate; }
            set { _orderDate = value; }
        }

        private User _provideTicketUser;
        [DataMember]
        public User ProvideTicketUser
        {
            get { return _provideTicketUser; }
            set { _provideTicketUser = value; }
        }

        private string _remark = string.Empty;
        [DataMember]
        public string Remark
        {
            get { return _remark; }
            set { _remark = value; }
        }

        private string _address = string.Empty;
        [DataMember]
        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }

        private string _customerStatus = string.Empty;
        [DataMember]
        public string CustomerStatus
        {
            get { return _customerStatus; }
            set { _customerStatus = value; }
        }

        private string _vendorStatus = string.Empty;
        [DataMember]
        public string VendorStatus
        {
            get { return _vendorStatus; }
            set { _vendorStatus = value; }
        }

        private decimal _intergral;
        [DataMember]
        public decimal Intergral
        {
            get { return _intergral; }
            set { _intergral = value; }
        }

        private Project _project;
        [DataMember]
        public Project Project
        {
            get { return _project; }
            set { _project = value; }
        }

        private SubProject _subProject;
        [DataMember]
        public SubProject SubProject
        {
            get { return _subProject; }
            set { _subProject = value; }
        }

        private string _content = string.Empty;
        [DataMember]
        public string Content
        {
            get { return _content; }
            set { _content = value; }
        }
        private Vendor _vendor;
        [DataMember]
        public Vendor Vendor
        {
            get { return _vendor; }
            set { _vendor = value; }
        }

        private Customer _customer;
        [DataMember]
        public Customer Customer
        {
            get { return _customer; }
            set { _customer = value; }
        }

        private string _paymentType = string.Empty;
        [DataMember]
        public string PaymentType
        {
            get { return _paymentType; }
            set { _paymentType = value; }
        }

        private BankAccount _bankAccount;
        [DataMember]
        public BankAccount BankAccount
        {
            get { return _bankAccount; }
            set { _bankAccount = value; }
        }

        private string _contactPerson = string.Empty;
        [DataMember]
        public string ContactPerson
        {
            get { return _contactPerson; }
            set { _contactPerson = value; }
        }

        private DateTime? deliveryDate = DateTime.Now;
        [DataMember]
        public DateTime? DeliveryDate
        {
            get { return this.deliveryDate; }
            set { this.deliveryDate = value; }
        }

        //private string _contactPersonTel = string.Empty;
        //[DataMember]
        //public string ContactPersonTel
        //{
        //    get { return _contactPersonTel; }
        //    set { _contactPersonTel = value; }
        //}   

        public string ContactPersonTel
        {
            get { return string.Format("{0}${1}", 联系电话, 移动电话); }
            set
            {
                string[] strs = value.Split('$');
                if (strs.Length == 2)
                {
                    联系电话 = strs[0];
                    移动电话 = strs[1];
                }
            }
        }

        private string _联系电话 = string.Empty;
        [DataMember]
        public string 联系电话
        {
            get { return _联系电话; }
            set { _联系电话 = value; }
        }

        private string _移动电话 = string.Empty;
        [DataMember]
        public string 移动电话
        {
            get { return _移动电话; }
            set { _移动电话 = value; }
        }

        //private string _contactPerson = string.Empty;
        //[DataMember]
        //public string ContactPerson
        //{
        //    get { return _contactPerson; }
        //    set { _contactPerson = value; }
        //}

        //private string _contactPersonTel = string.Empty;
        //[DataMember]
        //public string ContactPersonTel
        //{
        //    get { return _contactPersonTel; }
        //    set { _contactPersonTel = value; }
        //}

        //private string _address = string.Empty;
        //[DataMember]
        //public string Address
        //{
        //    get { return _address; }
        //    set { _address = value; }
        //}

        private string _creditTerm = string.Empty;
        [DataMember]
        public string CreditTerm
        {
            get { return _creditTerm; }
            set { _creditTerm = value; }
        }

        private string _customerName = string.Empty;
        [DataMember]
        public string CustomerName
        {
            get { return _customerName; }
            set { _customerName = value; }
        }

        private decimal _price;
        [DataMember]
        public decimal Price
        {
            get { return _price; }
            set { _price = value; }
        }

        private DateTime _projectDate = DateTime.Now;
        [DataMember]
        public DateTime ProjectDate
        {
            get { return _projectDate; }
            set { _projectDate = value; }
        }

        private decimal? _basePrice;
        [DataMember]
        public decimal? BasePrice
        {
            get { return _basePrice; }
            set { _basePrice = value; }
        }

        private int _qty;
        [DataMember]
        public int Qty
        {
            get { return _qty; }
            set { _qty = value; }
        }

        private Currency _currency;
        [DataMember]
        public Currency Currency
        {
            get { return _currency; }
            set { _currency = value; }
        }

        private string _voidCause = string.Empty;
        [DataMember]
        public string VoidCause
        {
            get { return _voidCause; }
            set { _voidCause = value; }
        }

        private string _status = "未付款";
        [DataMember]
        public string Status
        {
            get { return _status; }
            set { _status = value; }
        }

        private decimal? _vendorDiscount;
        [DataMember]
        public decimal? VendorDiscount
        {
            get { return _vendorDiscount; }
            set { _vendorDiscount = value; }
        }

        private User _salesman;
        [DataMember]
        public User Salesman
        {
            get { return _salesman; }
            set { _salesman = value; }
        }

        //private decimal _totalPrice;
        //[DataMember]
        public decimal TotalPrice
        {
            get 
            {
                return this.Price * this.Qty;
            }
            //get { return _totalPrice; }
            //set { _totalPrice = value; }
        }

        //[DataMember]
        public decimal? TotalVendorPrice
        {
            get
            {
                if (this.VendorDiscount != null)
                    return this.Price * (1 - this.VendorDiscount.Value/100) * this.Qty;
                else if (this.BasePrice != null)
                    return this.BasePrice.Value * this.Qty;
                else
                    return null;
            }
        }

        //[DataMember]
        public decimal? TotalProfit
        {
            get
            {
                if (this.VendorDiscount != null)
                    return this.Price * this.VendorDiscount.Value/100 * this.Qty;
                else if (this.BasePrice != null)
                    return (this.Price - this.BasePrice.Value) * this.Qty;
                else
                    return null;
            }
        }

        private decimal? _printTotalPrice;
        [DataMember]
        public decimal? PrintTotalPrice
        {
            get { return _printTotalPrice; }
            set { _printTotalPrice = value; }
        }

        public string 项目 
        {
            get 
            {
                if (SubProject == null)
                    if (Project != null)
                        return Project.Name;
                    else
                        return string.Empty;
                else
                    return string.Format("{0} - {1}", Project.Name, SubProject.Name);
            }
        }

        private string _日期 = null;
        public string 日期
        {
            get
            {
                if (_日期 == null)
                    return this.ProjectDate.ToString("yyyy/MM/dd");
                else
                    return _日期;
            }
            set 
            {
                _日期 = value;
            }
        }

        private string _projectText = string.Empty;
        [DataMember]
        public string ProjectText
        {
            get { return _projectText; }
            set { _projectText = value; }
        }

        private string _subProjectText = string.Empty;
        [DataMember]
        public string SubProjectText
        {
            get { return _subProjectText; }
            set { _subProjectText = value; }
        }

        private Guid? _subProjectID;
        [DataMember]
        public Guid? SubProjectID
        {
            get { return _subProjectID; }
            set { _subProjectID = value; }
        }

        private string _customerText = string.Empty;
        [DataMember]
        public string CustomerText
        {
            get { return _customerText; }
            set { _customerText = value; }
        }

        public override bool Equals(object obj)
        {
            OtherBusiness temp = obj as OtherBusiness;
            if (temp == null)
                return false;
            return (this.ID.Equals(temp.ID));
        }
    }
}
